//
//  BookManager.m
//  03-NSStringAndArrayHomeWork
//
//  Created by LL.F on 16/7/6.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "BookManager.h"
#import "Book.h"
@implementation BookManager

// 添加书籍
- (void)addBook:(Book *)book
{

    [self.libraryArray addObject:book];
    for (Book *book in self.libraryArray) {
        NSLog(@"%@--%.2lf", book.name, book.price);
    }
    
}
// 删除书籍
- (void)deleteBook:(Book *)book
{

    for (Book *sameBook in self.libraryArray) {
        if ([sameBook.name isEqualToString:book.name] && (sameBook.price == book.price)) {
            [self.libraryArray removeObject:sameBook];
        }
    }
    for (Book *book in self.libraryArray) {
        NSLog(@"%@--%.2lf", book.name, book.price);
    }
}
// 查找书籍
- (void)findBook:(Book *)book
{

    int flag = 0;
    for (Book *findBook in self.libraryArray) {
        if ([findBook.name isEqualToString:book.name] && (findBook.price == book.price)) {
            NSLog(@"您要查找的书籍是:%@--%.2lf", findBook.name, findBook.price);
            NSLog(@"请输入你想修改的价格:");
            CGFloat newPrice = 0;
            scanf("%lf", &newPrice);
            findBook.price = newPrice;
            NSLog(@"您修改完的结果为:%@--%.2lf", findBook.name, findBook.price);
              flag = 1;
          }
    }
    if (flag == 0) {
        NSLog(@"对不起,没找到您想查找的书籍");
    }
        
}
// 显示所有书籍清单
- (void)showAllBooks
{

    for (Book *book in self.libraryArray) {
        NSLog(@"%@", book.name);
    }
}
@end
